/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shellCommands;

import Sessions.EcomAdminRemote;
import Sessions.EcomCustomersRemote;
import java.util.List;
import java.util.StringTokenizer;

/**
 *
 * @author SOGOBA
 */
public class HelpCommand implements InterShell{
    ContextCommande cxtCmd;
    List<InterShell> commandes;

    public HelpCommand(ContextCommande contxtCommd, List<InterShell> cmds){
       cxtCmd=contxtCommd;
       commandes=cmds;
    }
    
    @Override
    public Commands getName() {
          return Commands.help;
    }

    @Override
    public String getShortDescription() {
        return "return the list of all commands";
    }
    
    public List<InterShell> getCommands(){
        return commandes;
    }
    
    @Override
    public void execute(String cmd,EcomAdminRemote ecomAdmin,EcomCustomersRemote ecomCust) throws Exception {
       try {
        StringTokenizer st = new StringTokenizer(cmd, " ");
        // Ignore cmd
        st.nextToken();
        // sans argument, on liste les magasins
        if (st.countTokens() == 0) {
            List <InterShell> cmds = getCommands();
            for (InterShell commd : cmds) {
               System.out.println(commd.getName()+ " - " + commd.getShortDescription());
        }
           }else {
            System.out.println("Command is not avalaible");
           }
      } catch (Exception ex) {
            System.out.println(ex.toString());
        }   }

}
